﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;

namespace TestUbigeoService
{
    [TestClass]
    public class TestUbigeo
    {
        [TestMethod]
        public void TestListaRegiones()
        {

            string url = "http://localhost:15256/Ubigeo.svc/ubigeo";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "GET";
            HttpWebResponse res = null;

            res = (HttpWebResponse)req.GetResponse();
            StreamReader reader = new StreamReader(res.GetResponseStream());
            string departamentoJson = reader.ReadToEnd();
            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Departamento> resultado = js.Deserialize<List<Departamento>>(departamentoJson);

            Assert.AreEqual(25, resultado.Count());

        }

        [TestMethod]
        public void TestListaProvincias()
        {

            string url = "http://localhost:15256/Ubigeo.svc/ubigeo/15";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "GET";
            HttpWebResponse res = null;

            res = (HttpWebResponse)req.GetResponse();
            StreamReader reader = new StreamReader(res.GetResponseStream());
            string provinciaJson = reader.ReadToEnd();
            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Provincia> resultado = js.Deserialize<List<Provincia>>(provinciaJson);

            Assert.AreEqual(10, resultado.Count());

        }

        [TestMethod]
        public void TestListaDistritos()
        {

            string url = "http://localhost:15256/Ubigeo.svc/ubigeo/15,01";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "GET";
            HttpWebResponse res = null;

            res = (HttpWebResponse)req.GetResponse();
            StreamReader reader = new StreamReader(res.GetResponseStream());
            string distritoJson = reader.ReadToEnd();
            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Distrito> resultado = js.Deserialize<List<Distrito>>(distritoJson);

            Assert.AreEqual(43, resultado.Count());

        }


    }
}
